<?php require 'header.php';
require 'pagination.php';
 ?>
		<div id="main" class="container">

			<div id="content" class="content section row">

				<div class="row sub-cat-list">
					<ul>
						<a href="http://tech.af/cats/1"><li><i class="fa fa-apple"></i> <span>Apple</span></li></a>
						<a href="http://tech.af/cats/3"><li><i class="fa fa-globe"></i> <span>Internet</span></li></a>						
						<a href="http://tech.af/cats/4"><li><i class="fa fa-windows"></i> <span>Microsoft</span></li></a>
						<a href="http://tech.af/cats/5"><li><i class="fa fa-mobile"></i> <span>Mobile</span></li></a>
						<a href="http://tech.af/cats/6"><li><i class="fa fa-graduation-cap"></i> <span>Sci-Tech</span></li></a>
						<a href="http://tech.af/cats/7"><li style="border-right: none;"><i class="fa fa-shield"></i> <span>Security</span></li></a>
					</ul>
				</div>
				<div class="col-md-8 bg-base col-lg-8 col-xl-9">
					<?php 
					$select_cat = $conn->prepare("SELECT * FROM `news_categories` WHERE id=:id");
					$select_cat->execute(array('id' => $_GET['cat_id']));
					$cat = $select_cat->fetch();
					?>
					<div class="ribbon ribbon-highlight">
						<ol class="breadcrumb ribbon-inner">
							<li>Categories</li><li class="active"><?php echo $cat['category_name']; ?></li>
						</ol>
					</div>
					<?php
					if(isset($_GET['page']))  
					{  
					  $page = $_GET['page'];  
					}  
					else  
					{  
					  $page = 1;  
					}
					$options = array(  
						'url'        => 'http://tech.af/cats/'.$_GET['cat_id'].'/*VAR*',  
					  //'url'        => 'http://tech.af/blog.php?cat_id='.$_GET['cat_id'].'&page=*VAR*',  
					  'db_handle'  => $conn,
					  'using_bound_params' => true    
					);
					try
					{
					    $pagination = new pagination($page, 'SELECT * FROM `news` WHERE category_id = :category_id ORDER BY pub_date DESC', $options);  
					}
					catch(paginationException $e)
					{
					    echo $e;
					    exit();
					}

					$pagination->bindParam(':category_id', $_GET['cat_id'], PDO::PARAM_STR, 12);  

					$pagination->execute();
					$result = $pagination->resultset->fetchAll();    


					
					?>
					<h1>In <?php echo $cat['category_name']; ?></h1>
					<hr>
					<div class="entries">
						<?php
							//$select_news = $conn->query("SELECT * FROM `news` ORDER BY pub_date DESC LIMIT 0,10");
							//while($row_news = $select_news->fetch()){
						foreach ($result as $row_news) {
						?>
						<article class="entry style-media media type-post">

							<figure class="media-object pull-left entry-thumbnail my-entry-thumbnail hidden-xs">

								<!-- to disable lazy loading, remove data-src and data-src-retina -->
								<img src="/author/images/<?php echo $row_news['img_name']; ?>" width="230" height="230" class="" alt="">

								<!--fallback for no javascript browsers-->
								<noscript>
									<img src="/author/images/<?php echo $row_news['img_name']; ?>" alt="">
								</noscript>

							</figure>

							<div class="media-body">

								<header class="entry-header">
									<h3 class="entry-title">
										<a href="/post/<?php echo $row_news['id']; ?>" rel="bookmark"><?php echo $row_news['title']; ?></a>
									</h3>

									<div class="entry-meta">
										<?php 
											$select_news_author = $conn->query("SELECT * FROM `users` WHERE id = '".$row_news['author_id']."'");
											$row_news_author = $select_news_author->fetch();
										?>
										<span class="author">by <a><?php echo $row_news_author['firstname'] . " " . $row_news_author['lastname']; ?></a></span>
										
										<span class="entry-date">/ <a href="#"><time datetime="2013-07-04T23:26:34+00:00"><?php echo @date("F jS Y",strtotime($row_news['pub_date'])); ?></time></a></span>
										<?php 
											$select_news_cat = $conn->query("SELECT * FROM news_categories WHERE id = '".$row_news['category_id']."'");
											$row_news_cat = $select_news_cat->fetch();
										?>
									</div>
								</header>

								<p>
									<?php echo substr($row_news['description'],1,150); ?><a href="/post/<?php echo $row_news['id']; ?>" class="more-link">Continue Reading<i class="fa fa icon-long-arrow-right"></i></a>
								</p>

							</div>

						</article>
						<?php } ?>
								
					</div><!--/.entris-->
					<div class="mypagination" style="text-align: center;">
				<?php    echo '<p>'.$pagination->links_html.'</p>'; ?>
				</div>
				</div><!--/.col-md-8.col-lg-8.col-xl-9-->

				<div class="sidebar col-md-4 col-lg-4 col-xl-3">

					<aside class="widget">
						<?php require 'sidebar-mostviewed.php'; ?>

					</aside><!--/.widget-->

					<aside id="reviewCarousel" class="widget carousel slide">

						<?php require 'rssbar.php'; ?>
					</aside><!--/.widget.carousel-->
					<aside class="widget">
						<?php require 'sidebar-ads.php'; ?>
					</aside><!--/.widget-->

				</div><!--/.sidebar col-md-4 col-lg-4 col-xl-3-->

			</div><!--/#content-->


			
		</div><!--#main.container-->

		<?php require 'footer.php'; ?>